//
//  SwitchViewController.m
//  shouji138.com
//
//  Created by administrator on 8/27/09.
//  Copyright 2009 __MyCompanyName__. All rights reserved.
//

#import "SwitchViewController.h"
#import "FirstViewController.h"
#import "SecondViewController.h"
#import "ManageViewController.h"
#import "ResultsViewController.h"
#import "StudentsViewController.h"
#import "QuestionsViewController.h"
#import "SrnTeacherAppDelegate.h"
#import "HandsRaisedViewController.h"
#import "StudentQuestionsViewController.h"
#import "StudentHistoryViewController.h"


@implementation SwitchViewController;
@synthesize firstviewcontroller;
@synthesize secondviewcontroller;
@synthesize manageviewcontroller;
@synthesize handsRaisedViewController;
@synthesize studentsQuestionViewController;

@synthesize resultsviewcontroller;
@synthesize studentsviewcontroller;
@synthesize questionsviewcontroller;
@synthesize studentHistoryViewController;


-(void)initView{
	NSLog(@"ttt");
	if(self.firstviewcontroller == nil){
		self.firstviewcontroller = [[FirstViewController alloc]initWithNibName:@"FirstView" bundle:nil];
	}
	[self removeAllView];
	[self.view insertSubview:self.firstviewcontroller.view atIndex:0];
}

-(void)showFirstView{
	if(self.firstviewcontroller == nil){
		self.firstviewcontroller = [[FirstViewController alloc]initWithNibName:@"FirstView" bundle:nil];
	}
	[self removeAllView];
	[self.view insertSubview:self.firstviewcontroller.view atIndex:0];
}

-(void)showSecondView{
	if(self.secondviewcontroller == nil){
		self.secondviewcontroller = [[SecondViewController alloc]initWithNibName:@"SecondView" bundle:nil];
	}
	[self removeAllView];
	[self.view insertSubview:self.secondviewcontroller.view atIndex:0];
}

-(void)showTabView{
	
	if(self.secondviewcontroller ==nil){
		self.secondviewcontroller = [[SecondViewController alloc]initWithNibName:@"SecondView" bundle:nil];
	}	
	if(self.manageviewcontroller ==nil){
		self.manageviewcontroller = [[ManageViewController alloc]initWithNibName:@"Manage" bundle:nil];	}
	
	if(self.resultsviewcontroller ==nil){
		self.resultsviewcontroller = [[ResultsViewController alloc]initWithNibName:@"ResultsView" bundle:nil];
		self.resultsviewcontroller.title = @"Votes";
	}
	
	if(self.studentsviewcontroller ==nil){
		self.studentsviewcontroller = [[StudentsViewController alloc]initWithNibName:@"StudentsView" bundle:nil];
		self.studentsviewcontroller.title = @"Voters";
	}
	
	if(self.questionsviewcontroller ==nil){
		self.questionsviewcontroller = [[StudentsViewController alloc]initWithNibName:@"QuestionsView" bundle:nil];
		self.questionsviewcontroller.title = @"Questions";
	}
	
	if(self.studentHistoryViewController ==nil){
		self.studentHistoryViewController = [[StudentHistoryViewController alloc]initWithNibName:@"StudentHistoryView" bundle:nil];
		self.studentHistoryViewController.title = @"History";
	}
	
	if(self.handsRaisedViewController ==nil){
		self.handsRaisedViewController = [[HandsRaisedViewController alloc]initWithNibName:@"HandsRaisedView" bundle:nil];
		self.handsRaisedViewController.title = @"Hands Raised";
	}
	
	if(self.studentsQuestionViewController ==nil){
		self.studentsQuestionViewController = [[StudentQuestionsViewController alloc]initWithNibName:@"StudentQuestionsView" bundle:nil];
		self.studentsQuestionViewController.title = @"Questions";
	}
	[self removeAllView];	
	//[self.view insertSubview:[SrnTeacherAppDelegate App].tabBarController.view atIndex:0];
	//[[SrnTeacherAppDelegate App].window removeView];
	[self.view removeFromSuperview];
	[[SrnTeacherAppDelegate App].window addSubview:[SrnTeacherAppDelegate App].tabBarController.view];
	//[[SrnTeacherAppDelegate App].tabBarController initView];	
}

-(void)removeAllView{
	for(NSInteger i=0;i<[self.view.subviews count];i++){
		[[self.view.subviews objectAtIndex:i] removeFromSuperview];
	}
}
/*
 // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        // Custom initialization
    }
    return self;
}
*/

/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/

/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
}
*/

/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
	
	// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
	// Release any retained subviews of the main view.
	// e.g. self.myOutlet = nil;
}


- (void)dealloc {
	[firstviewcontroller release];
	[secondviewcontroller release];
	[manageviewcontroller release];
	[resultsviewcontroller release];
	[studentsQuestionViewController release];
	[handsRaisedViewController release];
	[studentHistoryViewController release];
	[[SrnTeacherAppDelegate App].tabBarController release];
    [super dealloc];
}


@end
